package com.ocelot.san.utils;


import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public class FacesUtils {
	
	private static FacesUtils instance;
	
	public static FacesUtils getInstance() {
		if (instance==null) {
			instance = new FacesUtils(); 
		}
		return instance;
	}
	
	public void setManagedBeanInSession(String beanName, Object managedBean) {
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(beanName, managedBean);
	}

	public Object getManagedBeanInSession(String beanName) {
		return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(beanName);
	}
	
	public void removeManagedBeanInSession(String beanName) {
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(beanName, null);
	}

	public void addErrorMessage(String message) {
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message ,message));
	}

	public  void redirectToView(String view)  {
		FacesContext facesContext = FacesContext.getCurrentInstance(); 
		facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, view);
	}
	
}
